package com.newhis.config;

import org.apache.catalina.connector.RequestFacade;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 业务聚合
 *
 * @version [V2.0]
 * @package com.newhis.config;
 * @description:[用一句话描述该文件做什么]
 * @author: [zhuben]
 * @date: [2024-11-03 09:05]
 * @copyright: 2024 echovin.com
 */
public class WsInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
    public WsInterceptor() {
        super(Phase.RECEIVE);
    }

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
        RequestFacade requestFacade = (RequestFacade)message.get("HTTP.REQUEST");
        InputStream inputStream = message.getContent(InputStream.class);
        try {
            String string = IOUtils.toString(inputStream, "UTF-8");
            if (string.isEmpty()){
                return;
            }
            Document document = DocumentHelper.parseText(string);
            Element rootElement = document.getRootElement();
            Element bodyElement = rootElement.element("Body");
            List<Element> elements = bodyElement.elements();
            Element methodElement = elements.get(0);
            Element requestInfo = methodElement.element("requestInfo");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        message.setContent(InputStream.class, inputStream);
    }
}
